/*
 *
 * 轮播组件
 * 大轮播，小轮播，分类轮播
 *
 * */
import { SpecialModel } from '../../../models/special.js'
const ModeSpecial = new SpecialModel()
const App = getApp()
Component({
  /**
   * 组件的属性列表
   */
  externalClasses: ['ex-class'],
  options: {
    multipleSlots: true
  },
  properties: {
    type: String, // 轮播类型
    banner: Array // 轮播数据
  },
  /**
   * 组件的初始数据
   */
  data: {
    indicatorDots: false,
    circular: true,
    autoplay: true,
    interval: 5000,
    swiperCurrent: 0,
    duration: 1000
  },
  /**
   * 组件的方法列表
   */
  methods: {
    // 正品保证跳转
    topToIndexBanner: function() {
      const bannerUrl = 'https://admin.top1buyer.com/wxview/images'
      const query = 'genuine_2.jpg,license1.jpg'
      wx.navigateTo({
        url: `/pages/home/webview/index?bannerUrl=${bannerUrl}&query=${query}`
      })
    },
    // 点击轮播下方点切换
    doChange(e) {
      this.setData({
        swiperCurrent: e.currentTarget.dataset.i
      })
    },
    // 滑动轮播切换
    swiperChange(e) {
      this.setData({
        swiperCurrent: e.detail.current
      })
    },

    // 跳到专场判断获取权限
    getPreAuth(scode) {
      ModeSpecial.preSpecialAuth({ specialCode: scode }).then(res => {
        // 如果是预告并且开启
        const special = res.data.specialInfo
        // null 返回
        if (!special) {
          return
        }
        if (special.status == 0) {
          if (special.specialOpen == 1) {
            wx.navigateTo({
              url: `/pages/trailer/index?scode=${scode}`
            })
          }
        } else {
          wx.navigateTo({
            url: `/pages/activity/index?scode=${scode}`
          })
        }
      })
    },

    //最后疯抢
    topToCrazy(e) {
      const bannerInfo = e.currentTarget.dataset.banner
      wx.navigateTo({
        url: `/pages/activity/index?scode=${bannerInfo.specialCode}`
      })
    },

    //banner跳转
    topToBanner(e) {
      const bannerInfo = e.currentTarget.dataset.banner
      App.globalData.gio('track', 'ClassifyClick', {
        ClassifyType: bannerInfo.bannerType, // 轮播类型
        ClassifyName: bannerInfo.title, // 分类名称
        ClassifyId: bannerInfo.id // 分类id
      })
      if (bannerInfo.bannerType == 1) {
        // 专场获取是否可以点击进入
        const specialCode = bannerInfo.specialCode
        this.getPreAuth(specialCode)
      } else if (bannerInfo.bannerType == 2) {
        // 跳转到webview
        const bannerUrl = bannerInfo.bannerId
        wx.navigateTo({
          url: `/pages/home/webview/index?bannerUrl=${bannerUrl}`
        })
      } else if (bannerInfo.bannerType == 4) {
        // 跳转到小程序页面
        const url = bannerInfo.bannerId
        wx.navigateTo({
          url: url
        })
      } else if (bannerInfo.bannerType == 5) {
        // 跳转分类
        if (bannerInfo.bannerClass == 1) {
          wx.navigateTo({
            url: `/pages/search/index?searchText=${bannerInfo.detail}&type=click&normal=1`
          })
        } else if (bannerInfo.bannerClass == 3) {
          wx.navigateTo({
            url: `/pages/search/index?searchid=${bannerInfo.id}&searchText=${bannerInfo.title}&type=click`
          })
        }
      }
    }
  }
})
